package com.guoxin.chapter4.reentractlock.lockmethodtest3.test2;

import java.util.concurrent.locks.ReentrantLock;

public class Service {
	private ReentrantLock lock;
	
	public Service(boolean isFair){
		lock = new ReentrantLock(isFair);
	}
	
	public void serviceMethod() {
		try {
			System.out.println(lock.isHeldByCurrentThread());
			lock.lock();
			System.out.println(lock.isHeldByCurrentThread());
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();
		}
	}
}
